package com.lintcode.solution;

public class Solution_53 {
    public static void main(String[] args) {
        System.out.println(reverseWords("hello  "));
    }
    
    public static String reverseWords(String s) {
        if (s == null || "".equals(s)) {
            return "";
        }
        String[] arr = s.trim().split(" ");
        StringBuffer result = new StringBuffer();
        int length = arr.length;
        for (int i = 0; i < (length % 2 == 0 ? length / 2 : length / 2 + 1); i++) {
            String temp = arr[ i ];
            arr[ i ] = arr[ length - i - 1 ];
            arr[ length - i - 1 ] = temp;
        }
        for (String str : arr) {
            result.append(str).append(" ");
        }
        return result.toString().trim();
    }
}
